package pl.veneo.wigprofit {
	import pl.veneo.wigprofit.model.Configuration;
	import flash.utils.setTimeout;
	import eu.szemraj.logging.Log;
	import eu.szemraj.logging.LogLevel;
	import eu.szemraj.logging.channel.DevLoggerChannel;

	import pl.veneo.wigprofit.ctrl.ChartControler;
	import pl.veneo.wigprofit.model.ChartDataModel;
	import pl.veneo.wigprofit.view.ChartView;

	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.events.Event;

	/**
	 * @author Tomasz Swierszcz, fiodorkrk@gmail.com
	 */
	public class ChartApplication extends Sprite {
		public function ChartApplication() {
			stage.scaleMode = StageScaleMode.NO_SCALE;
			setTimeout(init, 1000);
			//addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(event : Event = null) : void {
			
			showStageDimentions();
			var dataurl : String = LoaderInfo(this.root.loaderInfo).parameters['dataurl'] || 'http://palmtube.com/data.xml';
			Configuration.getInstance().indexColor = Number("0x"+LoaderInfo(this.root.loaderInfo).parameters['color1']) || 0xAF1122;
			Configuration.getInstance().percentColor = Number("0x"+LoaderInfo(this.root.loaderInfo).parameters['color2']) || 0x1192FF;
			Configuration.getInstance().strongColor = Number("0x"+LoaderInfo(this.root.loaderInfo).parameters['color3']) || 0xEEEEEE;
			Configuration.getInstance().lightColor = Number("0x"+LoaderInfo(this.root.loaderInfo).parameters['color4']) || 0xBBBBBB;
			initializeLogger();
			buildApp(dataurl);
			
		}

		private function buildApp(url : String) : void {
			var model : ChartDataModel = new ChartDataModel(url);
			var view : ChartView = new ChartView(this);
			new ChartControler(model, view);
		}

		private function showStageDimentions() : void {
			
			trace(stage.stageWidth + ":" + stage.stageHeight);
		}

		private function initializeLogger() : void {
			Log.getLogger().addChannel(DevLoggerChannel.getInstance());
			Log.setLogLevel(LogLevel.DEFAULT);
			Log.info("INITIALIZED");
		}
	}
}
